﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class GameJudge : NetworkBehaviour
{
    public GameObject Player1;//本机
    public GameObject Player2;//对方

    float timer = 0;
    #region 单例
    public static GameJudge instance;
    public void Awake()
    {
        instance = this;
    }
    #endregion
    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (Player1 == null && GameObject.FindWithTag("Camp1") != null)
        {
            //此时Player1为客户端
            Player1 = GameObject.FindWithTag("Camp1").gameObject;
        }
        if (Player2 == null && GameObject.FindWithTag("Camp2") != null)
        {
            //此时Player2为服务端
            Player2 = GameObject.FindWithTag("Camp2").gameObject;

        }

        if (Player1 != null && Player2 != null)
        {
            CheckWin();
        }
    }

    private void CheckWin()
    {
        if (Player1.GetComponent<Camp>().currentHP <= 0)
        {
            LobbyUI.instance.SetInfoUI("You Lose", "退出",Application.Quit);
            Time.timeScale = 0;

        }
        else if (Player2.GetComponent<Camp>().currentHP <= 0)
        {
            LobbyUI.instance.SetInfoUI("You Win", "退出", Application.Quit);
            Time.timeScale = 0;
        }

    }
}
